/**
 * 重新定义console，并替换成tell命令
 * anchor:wos
 * dateTime: 2023年8月30日
 * 
 * 使用方法
 * @普通日志打印 tell.log('tell1','tell2','tell3',console)
 * @报错日志打印 tell.error('tell1','tell2','tell3')
 * @警告日志打印 tell.warn('tell1','tell2','tell3')
 * @信息日志打印 tell.info('tell1','tell2','tell3')
 * @版本日志 tell.version()
 */
import config from '@/config'

class Tell  {
    private checkEnv:boolean //是否为开发模式
    constructor(config:{'state':string}) {
        this.checkEnv = config?.state === 'build' ? false : true
    }
    //回显分和秒
    private showTime(){
        const currentTime = new Date()
        const minutes = currentTime.getMinutes()
        let minute = minutes < 10 ? '0' + minutes : minutes
        const seconds = currentTime.getSeconds()
        let second = seconds < 10 ? '0' + seconds : seconds
        return ` ${minute}:${second} `
    }
    public log(...str:any) {
        if (this.checkEnv) console.log(
            `%c${this.showTime()}`,
            'background-color:#089005;color:#FFF', 
            ...str 
        )
    }
    public error(...str:any) {
        if (this.checkEnv) console.error(
            `%c${this.showTime()}`,
            'background-color:#900508;color:#FFF',
            ...str
        )
    }
    public warn(...str:any) {
        if (this.checkEnv) console.warn(
            `%c${this.showTime()}`,
            'background-color:#908C05;color:#FFF',
            ...str
        )
    }
    public info(...str:any) {
        if (this.checkEnv) console.warn(
            `%c${this.showTime()}`,
            'background-color:#054E90;color:#FFF',
            ...str
        )
    }
    public assert = console.assert
    public clear = console.clear
    public context = (console as any).context
    public count = console.count
    public countReset = console.countReset
    public createTask = (console as any).createTask
    public debug = console.debug
    public dir = console.dir
    public dirxml = console.dirxml
    public group = console.group
    public groupCollapsed = console.groupCollapsed
    public groupEnd = console.groupEnd
    public memory = (console as any).memory
    public profile = console.profile
    public profileEnd = console.profileEnd
    public table = console.table
    public time = console.time
    public timeEnd = console.timeEnd
    public timeLog = console.timeLog
    public timeStamp = console.timeStamp
    public trace = console.trace
    public version() {
        if (this.checkEnv) console.log(
            '%c version: 1.0.0, author: wos, e-Mail: wosJiang@gmail.com ',
            'background-color:#8C0590;color:#FFF'
        )
    }
}
(window as any).tell = new Tell(config)